package com.blockchainenergy.manager.elecMeter;

import com.blockchainenergy.common.Result;
import com.blockchainenergy.mqtt.server.MqttService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/manager/elecMeter")
public class MElecMeterAPI {

    @Resource
    private MElecMeterService MElecMeterService;
    @Resource
    private MqttService mqttService;

    @PostMapping("/add")
    public Result addEnergy(@RequestBody AddElecMeterDto addElecMeterDto) {
        if (MElecMeterService.addElecMeter(addElecMeterDto)) {
            return Result.success("新建电表成功！");
        } else {
            return Result.fail(500, "已存在该电表！");
        }

    }

    @GetMapping("/info")
    public Result getAllElecMeterInfo() {
        return Result.success(MElecMeterService.getAllElecMeterInfo());
    }

    @GetMapping("/getElecID")
    public Result getElecID() {
        return Result.success(mqttService.getElecIDs());
    }

    @DeleteMapping("/del")
    public Result deleteRelease(@RequestBody DelElecMeterDto deleteDto) {
        MElecMeterService.deleteElecMeter(deleteDto.getElec_meter_id());
        return Result.success("删除成功！");
    }
}
